//
//  SinaNaviBaseController.swift
//  MySinaWeiBoSwiftProject
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 WangChen. All rights reserved.
//

import UIKit

class SinaNaviBaseController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    
    // MARK:
    // MARK: - 重写push方法,把back替换掉
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        let btnItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(backBtnDidClick))
        
        let count = childViewControllers.count
        if(count > 0){
            if let vc = viewController as? SinaBaseViewController{
                vc.naviItem.leftBarButtonItem = btnItem
                vc.hidesBottomBarWhenPushed = true
            }
//            //若是不继承base的naviBar
//            viewController.navigationItem.leftBarButtonItem = btnItem
//            viewController.hidesBottomBarWhenPushed = true
            
        }
        
        
        super.pushViewController(viewController, animated: animated)
        
        
    }

   
    // MARK:
    // MARK: - 点击返回触发监听
    func backBtnDidClick(){
        popViewController(animated: true)
    }
    

}
